//
//  ApprovedViewController.m
//  FMS
//
//  Created by Steven on 10/26/13.
//  Copyright (c) 2013 QGSVN. All rights reserved.
//

#import "ApprovedViewController.h"
#import "MaintenanceDetailedViewController.h"

@interface ApprovedViewController ()

@end

@implementation ApprovedViewController
@synthesize parent;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil parent:(id)_parent
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        dictLanguage = [ApplicationDelegate.arrayLanguage objectAtIndex:0];
        parent = _parent;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBar.hidden = YES;
    
    _lbMainTitle.text = [dictLanguage objectForKey:@"maintenance-mgmt.maintenance.status.pricing-received"];
    
    //set style for Approve button
    [_btnApprove setTitle:[dictLanguage objectForKey:@"maintenance-mgmt.detail.button-approve-costing"] forState:UIControlStateNormal];
    [_btnApprove setBackgroundImage:[AppDelegate imageFromColor:APPLE_BLUE_COLOR] forState:UIControlStateNormal];
    [_btnApprove setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btnApprove setBackgroundImage:[AppDelegate imageFromColor:[UIColor whiteColor]] forState:UIControlStateHighlighted];
    [_btnApprove setTitleColor:APPLE_BLUE_COLOR forState:UIControlStateHighlighted];
    
    //set style for Reject button
    [_btnReject setTitle:[dictLanguage objectForKey:@"maintenance-mgmt.detail.button-reject-costing"] forState:UIControlStateNormal];
    [_btnReject setBackgroundImage:[AppDelegate imageFromColor:APPLE_BLUE_COLOR] forState:UIControlStateNormal];
    [_btnReject setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_btnReject setBackgroundImage:[AppDelegate imageFromColor:[UIColor whiteColor]] forState:UIControlStateHighlighted];
    [_btnReject setTitleColor:APPLE_BLUE_COLOR forState:UIControlStateHighlighted];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (SYSTEM_VERSION_LESS_THAN(@"7.0")) ;
    else
        self.navigationController.view.superview.bounds = CGRectMake(0, 0, 400, 260);
}

- (IBAction)backPreviousView:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)handleApprove:(id)sender {
    [(MaintenanceDetailedViewController*)parent handleCostingRequest:APPROVE];
    [self dismissModalViewControllerAnimated:YES];
}

- (IBAction)handleReject:(id)sender {
    UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:nil message:[dictLanguage objectForKey:@"maintenance-mgmt.detail.confirm-reject-message"] delegate:self cancelButtonTitle:nil otherButtonTitles:[dictLanguage objectForKey:@"general.no"],[dictLanguage objectForKey:@"general.yes"], nil];
    [dialog show];
}

#pragma mark UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        //reject
        [self dismissModalViewControllerAnimated:YES];
        [(MaintenanceDetailedViewController*)parent handleCostingRequest:REJECT];
    }
}

@end
